//package com.mediacloud.app.newsmodule.fragment.navlive
//
//import android.os.Bundle
//import android.os.Handler
//import android.os.Message
//import android.text.TextUtils
//import android.util.Log
//import android.view.KeyEvent
//import android.view.View
//import android.view.ViewGroup
//import android.widget.FrameLayout
//import android.widget.Toast
//import androidx.recyclerview.widget.LinearLayoutManager
//import com.mediacloud.app.assembly.util.AppUtils
//import com.mediacloud.app.assembly.util.DateParse
//import com.mediacloud.app.cloud.ijkplayersdk.auth.URLAuth
//import com.mediacloud.app.cloud.ijkplayersdk.obj.MediaMusicItem
//import com.mediacloud.app.cloud.ijkplayersdk.video.VideoPlayer
//import com.mediacloud.app.controller.ControllerWarp
//import com.mediacloud.app.controller.live.IProgram
//import com.mediacloud.app.controller.live.OnLookBackTimeStampChangedListener
//import com.mediacloud.app.controller.live.ProgramMod
//import com.mediacloud.app.fbnavsk.navPaddingTopMatch
//import com.mediacloud.app.model.activity.FragmentActivityBase
//import com.mediacloud.app.model.interfaces.DataInvokeCallBack
//import com.mediacloud.app.model.news.*
//import com.mediacloud.app.model.news.kt.TypeX
//import com.mediacloud.app.model.utils.ViewUtils
//import com.mediacloud.app.model.view.floatwin.FloatButtonGroup
//import com.mediacloud.app.nav2.fragment.HqyNavFragment
//import com.mediacloud.app.newsmodule.R
//import com.mediacloud.app.newsmodule.activity.microlive.BaseRecyclerAdapter
//import com.mediacloud.app.newsmodule.model.VideoPlayObj
//import com.mediacloud.app.newsmodule.model.VideoPlayerListenerImpl
//import com.mediacloud.app.newsmodule.service.AudioItem
//import com.mediacloud.app.newsmodule.utils.*
//import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig
//import com.mediacloud.app.reslib.enums.XKey
//import com.tencent.mmkv.MMKV
//import com.utils.TyReportManager
//import com.utils.TyReportManager.Companion.getInstance
//import kotlinx.android.synthetic.main.navigate_livefragment.*
//import org.jetbrains.anko.collections.forEachWithIndex
//import org.json.JSONException
//import org.json.JSONObject
//import java.text.SimpleDateFormat
//import java.util.*
//import kotlin.collections.ArrayList
//
///**
// * 单页面直播视频
// *
// * 直播导航  带播放器的
// */
//class NavigateLiveFragmentC : HqyNavFragment(), DataInvokeCallBack<NavLiveData>, OnLookBackTimeStampChangedListener {
//
//    private var audioPlayer: AudioLiveView? = null
//    private var beforeIsPlay = false
//    private var dateAdapter: NavLiveProgramDateAdapter? = null
//    private var adapterChannelListH: NavLiveChannelTableAdapter? = null
//    private var adapterChannelListV: NavLiveDropDownListAdapter? = null
//
//    private var mLoadingView: View? = null
//    private var mEmptyContent: View? = null
//    private var pageIndex = 1
//
//    private var perPageSize = 200
//    private var dataInvoker: NewsListDataInvoker? = null
//    private var programFragment: NavigateLiveProgramFragment? = null
//    private var catalog: CatalogItem? = null
//
//    private var lineMap: MutableMap<String, String> = LinkedHashMap()
//    private var videoPlayObj = VideoPlayObj()
//    private var isAutoPlay = false
//
//
//    override fun getLayoutResID(): Int {
//        return R.layout.navigate_livefragment
//    }
//
//    override fun initView() {
//        mLoadingView = findViewById(R.id.mLoadingView)
//        mEmptyContent = findViewById(R.id.mEmptyContent)
//        initStateView()
//        mEmptyContent!!.setOnClickListener { loadData() }
//    }
//
//
//    override fun initOther() {
//        super.initOther()
//        catalog = fragmentArguments?.getParcelable("catalog")
//        dataInvoker = NewsListDataInvoker(this)
//
//        liveMediaPlayBackInvoker = LiveMediaPlayBackInvoker(object : DataInvokeCallBack<BaseMessageReciver> {
//            override fun success(data: BaseMessageReciver) {
//                if (activity == null || requireActivity().isFinishing || requireActivity().isDestroyed) {
//                    return
//                }
//                Log.w(TAG, "LivePlayBackUrlReciver success")
//                if (data.state) {
//                    val reciveData = data.orginData.optJSONObject("data")
//                    Log.w(TAG, "LivePlayBackUrlReciver success$data")
//                    if (reciveData?.optString(LiveMediaPlayBackInvoker.Url)?.isEmpty() == false) {
//                        val url = reciveData.optString(LiveMediaPlayBackInvoker.Url)
//                        player?.setErrorViewVisible(View.GONE)
//                        player?.stop()
//                        val replayObj = VideoPlayObj()
//                        val lineItem = VideoPlayObj.VideoLineItem()
//                        lineItem.setCdnEncypt(cdnEncrypt)
//                        replayObj.setCdn_iv(AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_iv)
//                        replayObj.setCdn_key(AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_key)
//                        lineItem.address = url
//                        lineItem.quality = getString(R.string.standard_quility)
//                        replayObj.mediaItem.add(lineItem)
//                        player?.mediaObjs?.clear()
//                        player?.addMediaObjs(replayObj)
//                        player?.isAutoPlay = true
//                        if (replayObj.mediaItem.size > 0) {
//                            player?.setBegin(true)
//                            player?.setLoadingViewBgTransparent()
//                            player?.playVideobj(0)
//                        }
//                        audioPlayer?.let {
//                            val items = ArrayList<MediaMusicItem>(1)
//                            val audioItem = AudioItem()
//                            audioItem.url = url
//                            audioItem.cdnEncrypt = cdnEncrypt
//                            audioItem.cdnIv = AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_iv
//                            audioItem.cdnKey = AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_key
//                            items.add(audioItem);
//                            it.setData(items)
//                        }
//                        player?.onLookBackResult(true)
//                    } else {
//                        fault(null)
//                    }
//                } else {
//                    fault(null)
//                }
//
//            }
//
//            override fun fault(data: Any?) {
//                if (activity == null || requireActivity().isFinishing || requireActivity().isDestroyed) {
//                    return
//                }
//                Log.w(TAG, "LivePlayBackUrlReciver fault")
//                ViewUtils.showSnackBar(mRootView, R.string.getplaybackurlerror)
//                player?.onLookBackResult(false)
//            }
//
//        })
//        loadData()
//    }
//
//    private fun loadData() {
//        dataInvoker?.getContentList(catalog?.catid ?: "", pageIndex, perPageSize, false, NavLiveData())
//    }
//
//
//    private fun initViews() {
//
//        isAutoPlay = MMKV.defaultMMKV().decodeBool(XKey.AUTO_PLAY, false);
//        player.autoPlay = isAutoPlay
//
//        //日期列表初始化
//        dateAdapter = NavLiveProgramDateAdapter(activity)
//        dateRecyclerView.layoutManager = LinearLayoutManager(requireContext(),LinearLayoutManager.HORIZONTAL,false)
//        dateRecyclerView.adapter = dateAdapter
//
//        //初始化横向滚动的频道列表
//        adapterChannelListH = NavLiveChannelTableAdapter(activity)
//        channelRecyclerViewH.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
//        channelRecyclerViewH.adapter = adapterChannelListH
//
//        //初始化纵向滚动的频道列表
//        adapterChannelListV = NavLiveDropDownListAdapter(requireActivity())
//        channelRecyclerViewV.layoutManager = LinearLayoutManager(requireContext())
//        channelRecyclerViewV.adapter = adapterChannelListV
//
//
//        switchIv.setOnClickListener {
//            it.isSelected = !it.isSelected
//            if (it.isSelected) {
//                allChannelTv.visibility = View.VISIBLE
//                channelRecyclerViewH.visibility = View.GONE
//                channelRecyclerViewV.visibility = View.VISIBLE
//            } else {
//                allChannelTv.visibility = View.GONE
//                channelRecyclerViewV.visibility = View.GONE
//                channelRecyclerViewH.visibility = View.VISIBLE
//            }
//
//        }
//
//        dateAdapter?.setItemClickListener { index, _, _ ->
//            if (index != dateAdapter!!.selectedIndex) {
//                val item = dateAdapter!!.getItem(index)
//                dateAdapter!!.selectedIndex = index
//                var channel = if (adapterChannelListH!!.data.size > 0) adapterChannelListH!!.data!![adapterChannelListH!!.selectedIndex] else null
//                channel?.let {
//                    programFragment?.updateDate(it, it.vid ?: "", "${item.date}", false, "${it.id}", it.title ?: "")
//                }
//            }
//        }
//
//        val channelClickListener = { index: Int, _: Boolean, adapter: BaseRecyclerAdapter<*> ->
//            if (index != adapterChannelListH!!.selectedIndex) {
//                adapterChannelListH!!.selectedIndex = index
//                adapterChannelListV!!.selectedIndex = index
//                switchChannel(adapterChannelListH!!.getItem(index))
//                //取节目单
//                val item = dateAdapter!!.getItem(dateAdapter!!.selectedIndex)
//                if (programFragment == null) {
//                    addProgramListFragment(
//                        item.date!!,
//                        adapterChannelListH!!.getItem(index).vid,
//                        "${adapterChannelListH!!.getItem(index).id}",
//                        adapterChannelListH!!.getItem(index).title,
//                        adapterChannelListH!!.getItem(index)
//                    )
//                }
//                programFragment?.updateDate(
//                    adapterChannelListH!!.getItem(index),
//                    adapterChannelListH!!.getItem(index).vid,
//                    "${item.date}",
//                    isChangeChannel = true,
//                    "${adapterChannelListH!!.getItem(index).id}",
//                    adapterChannelListH!!.getItem(index).title
//                )
//                if (adapter is NavLiveDropDownListAdapter)
//                    channelRecyclerViewV.scrollToPosition(index)
//            }
//        }
//        adapterChannelListH!!.setItemClickListener(channelClickListener)
//        adapterChannelListV!!.setItemClickListener(channelClickListener)
//    }
//
//    private fun initappfacContent() {
//        mLoadingView?.visibility = View.GONE
//        mEmptyContent?.visibility = View.GONE
//    }
//
//    private var detailInvoker: NewsDetailInvoker? = null
//
//    /**
//     * 频道切换
//     */
//    private fun switchChannel(articleItem: ArticleItem) {
//        //暂停视频或者音频的播放
//        player?.let {
//            it.stop()
//            it.release()
//        }
//        audioPlayer?.let {
//            it.stop()
//            it.release()
//        }
//        //获取数据详情
//        detailInvoker = NewsDetailInvoker(object : DataInvokeCallBack<ArticleItemReciver> {
//            override fun success(data: ArticleItemReciver) {
//                doLiveChannelPlayHandle(data.articleItem ?: null)
////                showStateView(TYPE_LOADING, false)
//            }
//
//            override fun fault(data: Any?) {
//                showErrorView()
//            }
//        })
//        detailInvoker!!.getArticleById("" + articleItem.id, catalog?.catid)
//    }
//
//    private fun showErrorView() {
//        // player?.centerBigPlay!!.visibility = View.VISIBLE
////        showStateView(TYPE_NET_NOT_GIVE_FORCE, false)
//        player!!.stop()
//        player!!.setErrorViewVisible(View.VISIBLE)
//        ViewUtils.showSnackBar(mRootView, R.string.getlivestreamerror)
//    }
//
//    private var cdnEncrypt: String? = null
//
//    /**
//     * 视频直播
//     */
//    private fun playVideoLive(articleItem: ArticleItem) {
//        videoPlayerContainer.removeAllViews()
//        player = VideoPlayer(requireContext())
//        player?.setPlayControllerType(ControllerWarp.TYPE_LIVE)
//        player?.setLiveProgressBarTimeLimit(AppFactoryGlobalConfig.getAppServerConfigInfo(context).otherFunction.live_progress_bar_time_limit)
//        player?.iPlayerProgramLookBack = this
//        player?.isLive = true
//        player?.hideButtonBack()
//        val p = FrameLayout.LayoutParams(
//            FrameLayout.LayoutParams.MATCH_PARENT,
//            FrameLayout.LayoutParams.MATCH_PARENT
//        )
//        videoPlayerContainer.addView(player, p)
//        try {
//            setVideoPlayerListener()
//            player?.isAutoPlay = false
//            //  player?.centerBigPlay!!.visibility = if (isAutoPlay) View.GONE else View.VISIBLE
//            player?.showVideoTitleInfo(articleItem.title)
//            val video = JSONObject(articleItem.video)
//            val tsAddress = VideoAddressGet.getAddress(video)
//            if (tsAddress?.length() ?: 0 > 0)
//                player?.stop()
//            else {
//                showErrorView()
//                return
//            }
//            videoPlayObj.mediaItem.clear()
//            videoPlayObj.setTitle(articleItem.title)
//            videoPlayObj.setVID(articleItem.vid)
//            val poster = video.optString("poster", "")
//            player?.setPoster(
//                poster,
//                AppFactoryGlobalConfig.getDefaultImageLoadDrawable(),
//                AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.img_cut
//            )
//            cdnEncrypt = video.optString("cdnConfigEncrypt")
//            videoPlayObj.setCdn_iv(AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_iv)
//            videoPlayObj.setCdn_key(AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_key)
//            val currentTenantid = resources.getString(R.string.tenantid)
//            val jxtenantid = resources.getString(R.string.tenant_jiangxi)
//            for (i in 0 until tsAddress.length()) {
//                val line = tsAddress.optJSONObject(i)
//                val title = line.optString("title")
//                val url: String
//                url = if (currentTenantid == jxtenantid)
//                    line.optString("liveStream")
//                else
//                    line.optString("url")
//                lineMap[title] = line.optString(LiveMediaPlayBackInvoker.ReviewUrl)
//                val lineItem = VideoPlayObj.VideoLineItem()
//                lineItem.address = url
//                lineItem.quality = title
//                lineItem.setCdnEncypt(cdnEncrypt)
//                videoPlayObj.mediaItem.add(lineItem)
//            }
//            programFragment?.isFirstPlay = true
//            player!!.mediaObjs.clear()
//            player!!.addMediaObjs(videoPlayObj)
//            if (videoPlayObj.mediaItem.size > 0)
//                player!!.playVideobj(0)
//            isAutoPlay = true
//        } catch (e: Exception) {
//            e.printStackTrace()
//            Log.e(TAG, "" + e.message)
//            showErrorView()
//        }
//    }
//
//    /**
//     * Play audio live
//     *
//     */
//    private fun playAudioLive(item: ArticleItem?) {
//        videoPlayerContainer.removeAllViews()
//        KillMusicUtils.stopAPS(requireActivity())
//        audioPlayer = AudioLiveView(requireContext())
//        audioPlayer?.setBackgroundImageUrl(radioImageUrl)
//        videoPlayerContainer.addView(audioPlayer)
//        if (item == null) {
//            audioPlayer?.showPlayError()
//            return
//        }
//        audioPlayer?.setLogo(item.logo)
//        try {
//            val `object` = JSONObject(item.audio)
//            val array = `object`.getJSONArray("ANDROID")
//            cdnEncrypt = `object`.getString("cdnConfigEncrypt")
//            val items = ArrayList<MediaMusicItem>()
//            for (i in 0 until array.length()) {
//                val obj = array.getJSONObject(i)
//                val audioItem = AudioItem()
//                audioItem.url = obj.getString("url")
//                audioItem.cdnEncrypt = cdnEncrypt
//                audioItem.cdnIv = AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_iv
//                audioItem.cdnKey = AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_key
//                items.add(audioItem)
//            }
//            audioPlayer?.setData(items)
//        } catch (e: JSONException) {
//            audioPlayer?.showPlayError()
//        }
//
//        /**
//         * There was no code to write, write more comments,so to keep the busy。
//         *
//         */
//    }
//
//    public var mCurrentLiveArticleItem: ArticleItem? = null
//
//    /**
//     * 播放选定的频道
//     */
//    private fun doLiveChannelPlayHandle(articleItem: ArticleItem?) {
//        mCurrentLiveArticleItem = articleItem
//        this.isLive = true
//        if (articleItem == null) {
//            showErrorView()
//            return
//        }
//        when (articleItem.type) {
//            TypeX.NEWS.LIVE_VIDEO -> {
//                view_tv_page(mCurrentLiveArticleItem)
//                playVideoLive(articleItem)
//            }
//            TypeX.NEWS.LIVE_AUDIO -> {
//                playAudioLive(articleItem)
//            }
//        }
//
//    }
//
//    fun view_tv_page(articleItem: ArticleItem?) {
//        if (articleItem != null) {
//            TyReportManager.getInstance().view_tv_page(
//                articleItem
//            )
//        }
//    }
//
//    private fun updateDateList() {
//        val date = Date()
//        val dateFormat = SimpleDateFormat("yyyyMMdd")
//        val today = dateFormat.format(date)
//        val find = { index: Int, item: NavDateItem ->
//            if (item.date == today) {
//                item.summary = "今"
//                dateAdapter!!.selectedIndex = index
//            }
//        }
//        dateAdapter!!.data.forEachWithIndex(find)
//        dateAdapter!!.notifyDataSetChanged()
//        programDateList!!.post {
//            if (dateAdapter!!.data.size > 0)
//                programDateList!!.scrollToPosition(dateAdapter!!.selectedIndex)
//        }
//
//    }
//
//    private fun updateTableChannel() {
//        adapterChannelListH!!.notifyDataSetChanged()
//        if (adapterChannelListH!!.data.size > 0) {
//            switchChannel(adapterChannelListH!!.getItem(0))
//        }
//    }
//
//
//    private fun addProgramListFragment(videoId: String, date: String, contentId: String, channelName: String, item: ArticleItem) {
//        programFragment = NavigateLiveProgramFragment()
//        val bundle = Bundle()
//        bundle.putString(NavigateLiveProgramFragment.VideoID, videoId)
//        bundle.putParcelable(NavigateLiveProgramFragment.Item, item)
//        bundle.putString(NavigateLiveProgramFragment.Date, date)
//        bundle.putString(NavigateLiveProgramFragment.ContentID, contentId)
//        bundle.putString(NavigateLiveProgramFragment.ChannelName, channelName)
//        programFragment!!.arguments = bundle
//        childFragmentManager.beginTransaction().add(R.id.appfacProgramList, programFragment!!).commitNowAllowingStateLoss()
//    }
//
//    var fragmentIsVisiable = true
//    override fun choosed() {
//        super.choosed()
//        if (beforeIsPlay) {
//            player?.resume()
//            audioPlayer?.start()
//        }
//    }
//
//    override fun onPause() {
//        super.onPause()
//        unChooseHandle()
//    }
//
//    override fun onResume() {
//        super.onResume()
//        if (hadChoosed)
//            choosed()
//    }
//
//
//    override fun unChosoed() {
//        super.unChosoed()
//        unChooseHandle()
//    }
//
//    private fun unChooseHandle() {
//
//
//        val isPlay: Boolean = ((player != null && player!!.isPlaying) ||
//                (audioPlayer != null && audioPlayer!!.isPlaying))
//        if (isPlay) {
//            beforeIsPlay = true
//            player?.pagePause = true
//            player?.pause()
//            audioPlayer?.pause()
//        } else {
//            beforeIsPlay = false
//        }
//    }
//
//    override fun onDestroyView() {
//        val activity = requireActivity()
//        if (activity is FragmentActivityBase) {
//            activity.setOnKeyCodeListener(null, true)
//        }
//        player?.iPlayerProgramLookBack = null
//        dateAdapter?.setItemClickListener(null)
//        adapterChannelListH?.setItemClickListener(null)
//        adapterChannelListV?.setItemClickListener(null)
//        quit_tv_playback()
//        quit_tv_live(mCurrentLiveArticleItem)
//        super.onDestroyView()
//    }
//
//    override fun onDestroy() {
//        detailInvoker?.destory()
//        dataInvoker?.destory()
//        player?.stop()
//        audioPlayer?.stop()
//        if (programFragment != null) {
//            childFragmentManager.beginTransaction().remove(programFragment!!).commitNowAllowingStateLoss()
//        }
//        liveMediaPlayBackInvoker?.destory()
//        updateHandle.removeMessages(2)
//        super.onDestroy()
//    }
//
//
//    override fun onHiddenChanged(hidden: Boolean) {
//        super.onHiddenChanged(hidden)
//        if (hidden) {
//            fragmentIsVisiable = false
//            unChooseHandle()
//        } else fragmentIsVisiable = true
//    }
//
//    override fun success(data: NavLiveData) {
//        if (activity == null || requireActivity().isFinishing || requireActivity().isDestroyed) {
//            return
//        }
//        val state = data.state
//        if (state) {
//            //必须 的
//            val floatData = data.orginData?.optJSONObject("data")
//            if (pageIndex == 1) {
//                if (FloatButtonGroup.haveFloatField(floatData)) {
//                    initFloatWin(floatData)
//                } else {
//                    hideFloatWin()
//                }
//            }
//
//            initappfacContent()
//            updateDateList()
//            updateTableChannel()
//            if (data.articleList!!.size > 0) {
//                adapterChannelListH!!.data.clear()
//                adapterChannelListH!!.data.addAll(data.articleList)
//
//                updateTableChannel()
//            }
//            if (data.weekList?.isEmpty() == false) {
//                dateAdapter!!.data.addAll(data.weekList!!)
//                updateDateList()
//            }
//            if (data.weekList?.isEmpty() == false && data.articleList?.isEmpty() == false) {
//                val videoId: String? = data.articleList[0].vid
//                val date = data.weekList!![dateAdapter!!.selectedIndex].date
//                if (date?.isEmpty() == false) {
//                    if (adapterChannelListH!!.getItem(0) != null)
//                        addProgramListFragment(
//                            videoId + "",
//                            date,
//                            "${adapterChannelListH!!.getItem(0).id}",
//                            adapterChannelListH!!.getItem(0).title,
//                            data.articleList[0]
//                        )
//
//                }
//            }
//            //
//
//
//            data.navigate?.let {
//                it["style_other"]?.let {
//                    val style = it as HashMap<String, String>
//                    radioImageUrl = style["radio_bitmap"]
//                    audioPlayer?.setBackgroundImageUrl(radioImageUrl)
//                }
//            }
//        }
//        Log.v(TAG, "radioImageUrl$radioImageUrl")
//    }
//
//    private var radioImageUrl: String? = null
//
//    override fun fault(data: Any?) {
//        if (activity == null || requireActivity().isFinishing || requireActivity().isDestroyed) {
//            return
//        }
//        println("error" + data?.toString())
//        mLoadingView?.visibility = View.GONE
//        mEmptyContent?.visibility = View.VISIBLE
////        showStateView(TYPE_NET_NOT_GIVE_FORCE, false)
//    }
//
//    private var liveMediaPlayBackInvoker: LiveMediaPlayBackInvoker? = null
//
//    private val updateHandle: Handler = object : Handler() {
//        override fun handleMessage(msg: Message) {
//            super.handleMessage(msg)
//            if (msg.what == 1) {
//                if (programList != null && programList!!.size > 0) {
//                    if (msg.arg1 < programList!!.size - 1) {
//                        val item2: ProgramListItem = programList!!.get(msg.arg1 + 1)
//                        handleReplay(item2)
//                    } else {
//                        this.removeMessages(1)
//                    }
//                }
//            }
//        }
//    }
//
//    var index = 0
//    var programListItem: ProgramListItem? = null
//    internal fun handleReplay(item: ProgramListItem) {
//        quit_tv_playback()
//        quit_tv_live(mCurrentLiveArticleItem)
//        this.programListItem = item
//        isLive = false
//        if (programFragment != null) programFragment?.freshAdapter(item)
//        try {
//            updateHandle.removeMessages(1)
//            if (programList != null) {
//                for (i in programList!!.indices) {
//                    if (programList!![i].id == item.id) {
//                        index = i
//                        break
//                    }
//                }
//            }
//            updateHandle.postDelayed({
//                val now = System.currentTimeMillis()
//                val startTime = DateParse.parseDate(item.starttime, null)
//                val endDate = DateParse.parseDate(item.endtime, null)
//                var delay = 0L
//                delay = if (now > endDate.time) {
//                    endDate.time - startTime.time
//                } else {
//                    if (now > startTime.time) {
//                        endDate.time - now
//                    } else {
//                        endDate.time - startTime.time
//                    }
//                }
//
//                if (delay > 0L) {
//                    val msg = Message()
//                    msg.what = 1
//                    msg.arg1 = index
//                    updateHandle.sendMessageDelayed(msg, delay)
//                }
//                Log.e("mwl", "navlivefragment--index:$index,delay:$delay,programListItems.size:${programList?.size},isPlaying:${item.isPlaying}")
//            }, 0)
//            player?.setErrorViewVisible(View.GONE)
//            player?.stop()
//            val state = if (item.playerStart > 0L) { //startLong！=0 说明是来自进度条节目单
//                if (System.currentTimeMillis() > item.playerStart) {
//                    ProgramListItem.GuideItemState.REPLAY
//                } else {
//                    ProgramListItem.GuideItemState.LIVE
//                }
//            } else if (item.playerStart == -1L) {
//                ProgramListItem.GuideItemState.LIVE
//            } else {
//                ProgramListItem.getItemState(item)
//            }
//            if (item.isPlaying == 0) {
//                player?.setLiveIvPoser(item.placeholder, 0)
//                if (ProgramListItem.GuideItemState.REPLAY == state) {
//                    if (item.playerStart == 0L) {  //startLong==0 说明不是来自进度条节目单
//                        player?.setProgramComponentLookBack(item.starttime)
//                    }
//                }
//            } else {
//                player?.isAutoPlay = true
//                player?.setLiveIvPoser(item.placeholder, 8)
//
//                val keySet = lineMap.entries
//                val iterator = keySet.iterator()
//
//                if (ProgramListItem.GuideItemState.REPLAY == state) {
//                    while (iterator.hasNext()) {
//                        val entry = iterator.next()
////
//                        val url = entry.value
//
//                        var startDate: Date
//                        var endDate: Date? = null
//                        if (item.playerStart != 0L) {
//                            startDate = Date(item.playerStart)
//                        } else {
//                            startDate = DateParse.parseDate(item.starttime, null)
//                            endDate = DateParse.parseDate(item.endtime, null)
//                        }
//
//                        liveMediaPlayBackInvoker?.getLiveUrlPlayBackUrl(
//                            url,
//                            URLAuth.EncrptMode(
//                                cdnEncrypt,
//                                AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_key,
//                                AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_iv
//                            )?.code,
//                            startDate.time,
//                            endDate?.time ?: 0L
//                        )
//                        if (item.playerStart == 0L) {  //startLong==0 说明不是来自进度条节目单
//                            player?.setProgramComponentLookBack(item.starttime)
//                        }
//                        break
//                    }
//                } else if (ProgramListItem.GuideItemState.LIVE == state) {
//                    player?.mediaObjs?.clear()
//                    player?.isAutoPlay = true
//                    player?.isLiveReplay = false
//                    player?.addMediaObjs(videoPlayObj)
//                    if (videoPlayObj.mediaItem.size > 0) {
//                        player?.setBegin(true)
//                        player?.playVideobj(0)
//                    }
//                    if (item.playerStart == 0L) {  //startLong==0 说明不是来自进度条节目单
//                        player?.setProgramComponentLookBack(null)
//                    }
//                    player?.onLookBackResult(true)
//                }
//                setVideoPlayerListener()
//            }
//        } catch (e: Exception) {
//            e.printStackTrace()
//        }
//    }
//
//    var isLive = false
//
//    var isStartPlayLive = false
//    var mTyReportStartPlayTime: Long = 0
//    var mTyReportEndPlayTime: Long = 0
//
//    var isStartPlaybackLive = false
//    var mTyReportStartPlaybackTime: Long = 0
//    var mTyReportEndPlaybackTime: Long = 0
//    fun watch_tv_video(articleItem: ArticleItem?) {
//        if (isLive) {
//            quit_tv_live(mCurrentLiveArticleItem)
//            quit_tv_playback()
//            if (articleItem != null) {
//                if (!isStartPlayLive) {
//                    TyReportManager.getInstance()
//                        .watch_tv_live(
//                            "${articleItem?.id ?: "0"}",
//                            articleItem?.title,
//                            articleItem?.getType().toString(),
//                            TyReportManager.getInstance().getPageName(),
//                            TyReportManager.getInstance().getPageId(),
//                            if (TextUtils.isEmpty(articleItem.referName)) {
//                                AppUtils.getAppName(context)
//                            } else {
//                                articleItem.referName
//                            }
//                        )
//                    mTyReportStartPlayTime = System.currentTimeMillis()
//                    mTyReportEndPlayTime = mTyReportStartPlayTime
//                    isStartPlayLive = true
//                }
//            }
//        }
//    }
//
//    fun quit_tv_live(articleItem: ArticleItem?) {
//        if (isLive) {
//            if (articleItem != null) {
//                if (isStartPlayLive) {
//                    if (mTyReportStartPlayTime > 0) {
//                        mTyReportEndPlayTime = System.currentTimeMillis()
//                        TyReportManager.getInstance()
//                            .quit_tv_live(
//                                "${articleItem?.id ?: "0"}",
//                                articleItem?.title,
//                                articleItem?.getType().toString(),
//                                TyReportManager.getInstance().getPageName(),
//                                TyReportManager.getInstance().getPageId(),
//                                if (TextUtils.isEmpty(articleItem.referName)) {
//                                    AppUtils.getAppName(context)
//                                } else {
//                                    articleItem.referName
//                                }, mTyReportEndPlayTime - mTyReportStartPlayTime
//                            )
//                    }
//                    isStartPlayLive = false
//                }
//            }
//        }
//    }
//
//    fun watch_tv_playback() {
//        quit_tv_live(mCurrentLiveArticleItem)
//        quit_tv_playback()
//
//
//        if (!isLive) {
//            if (mCurrentLiveArticleItem != null) {
//                if (!isStartPlaybackLive) {
//                    TyReportManager.getInstance()
//                        .watch_tv_playback(
//                            "${mCurrentLiveArticleItem?.id ?: "0"}",
//                            mCurrentLiveArticleItem?.title,
//                            mCurrentLiveArticleItem?.getType().toString(),
//                            programListItem?.name,
//                            programListItem?.playTime ?: programListItem?.starttime,
//                            TyReportManager.getInstance().getPageName(),
//                            TyReportManager.getInstance().getPageId(),
//                            if (TextUtils.isEmpty(mCurrentLiveArticleItem?.referName)) {
//                                AppUtils.getAppName(context)
//                            } else {
//                                mCurrentLiveArticleItem?.referName
//                            }
//                        )
//                    mTyReportStartPlaybackTime = System.currentTimeMillis()
//                    mTyReportEndPlaybackTime = mTyReportStartPlaybackTime
//                    isStartPlaybackLive = true
//                }
//            }
//        }
//    }
//
//    fun quit_tv_playback() {
//        if (!isLive) {
//            if (mCurrentLiveArticleItem != null) {
//                if (isStartPlaybackLive) {
//                    if (mTyReportStartPlaybackTime > 0) {
//                        mTyReportEndPlaybackTime = System.currentTimeMillis()
//                        TyReportManager.getInstance()
//                            .quit_watch_tv_playback(
//                                "${mCurrentLiveArticleItem?.id ?: "0"}",
//                                mCurrentLiveArticleItem?.title,
//                                mCurrentLiveArticleItem?.getType().toString(),
//                                programListItem?.name,
//                                programListItem?.playTime ?: programListItem?.starttime,
//                                TyReportManager.getInstance().getPageName(),
//                                TyReportManager.getInstance().getPageId(),
//                                if (TextUtils.isEmpty(mCurrentLiveArticleItem?.referName)) {
//                                    AppUtils.getAppName(context)
//                                } else {
//                                    mCurrentLiveArticleItem?.referName
//                                },
//                                mTyReportEndPlaybackTime - mTyReportStartPlaybackTime
//                            )
//                    }
//                    isStartPlaybackLive = false
//                }
//            }
//        }
//    }
//
//    private val playerListener = object : VideoPlayerListenerImpl() {
//        override fun onPrepared(currentMediaIndex: Int) {
//            super.onPrepared(currentMediaIndex)
//            if (programFragment != null) {
//                programFragment?.setPlay()
//            }
//            player?.toggleFullScreenEnable(true)
//            if (fragmentIsVisiable) player?.resume()
//            else player?.pause()
//
//            if (isLive) {
//                watch_tv_video(mCurrentLiveArticleItem)
//            } else {
//                watch_tv_playback()
//            }
//        }
//
//        override fun ontoggleFullScreen(currentMediaIndex: Int, isFullScreen: Boolean) {
////            super.ontoggleFullScreen(currentMediaIndex, isFullScreen)
////            Log.v(TAG,"ontoggleFullScreen"+isFullScreen)
////            if (activity is IStatusBarColor) {
////                (activity as IStatusBarColor).refreshStatusBarColor()
////            }
//
//            if (isFullScreen) {
//                enterFullScreen()
//            } else {
//                exitFullScreen()
//            }
//            programFragment?.needScrollToPosition = true
//            programFragment?.scrollToPosition()
//        }
//
//        override fun onError(currentMediaIndex: Int, arg1: Int, arg2: Int) {
//            super.onError(currentMediaIndex, arg1, arg2)
//            getInstance().report_tv_live_problem(
//                "${mCurrentLiveArticleItem?.id}",
//                "${mCurrentLiveArticleItem?.title}", "${mCurrentLiveArticleItem?.type}",
//                getInstance().getPageName(),
//                getInstance().getPageId(), "", "error"
//            )
//            ReportManager.getInstance().report_tvshow_live_problem("", "", "电视直播异常", "", "", "", "", "", "", "")
//        }
//    }
//
//
//    private fun enterFullScreen() {
//        player?.let {
//            val parent = it.parent as ViewGroup
//            parent.removeView(it)
//            val view = requireActivity().findViewById<ViewGroup>(android.R.id.content)
//            view.addView(it)
//        }
//    }
//
//
//    private fun exitFullScreen() {
//        player?.let {
//            val parent = it.parent as ViewGroup
//            parent.removeView(it)
//            videoPlayerContainer.addView(it)
//        }
//    }
//
//    private fun setVideoPlayerListener() {
//        player?.toggleFullScreenEnable(false)
//        player?.setOnPlayerListener(playerListener)
//    }
//
//    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
//        super.onViewCreated(view, savedInstanceState)
//        this.navPaddingTopMatch()
//        val activity = requireActivity()
//        if (activity is FragmentActivityBase) {
//            activity.setOnKeyCodeListener(FragmentActivityBase.OnKeyListener { keyCode, event ->
//                return@OnKeyListener onKeyDown(keyCode, event)
//            }, true)
//        }
//    }
//
//    protected var mExitTime: Long = 0
//
//    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
//
//        when (keyCode) {
//            KeyEvent.KEYCODE_BACK -> {
//                if (player != null && player!!.isFullScreen) {
//                    player!!.toggleFullScreen()
//                    return true
//                }
//                return false
//            }
//        }
//        return false
//    }
//
//    fun exitApp() {
//        if (System.currentTimeMillis() - mExitTime > 2000) {
//            com.utils.ToastUtil.showToastCenter(requireContext(), R.string.exit_app, Toast.LENGTH_SHORT)
//        } else {
//            requireActivity().finish()
//        }
//        mExitTime = System.currentTimeMillis()
//    }
//
//    private var programList: MutableList<ProgramListItem>? = null
//    fun setPrograms(programList: MutableList<ProgramListItem>?) {
//        this.programList = programList
//        val programs: MutableList<IProgram> = ArrayList()
//        programList?.forEach {
//            programs.add(ProgramMod(it.name, it.starttime))
//        }
//        player?.setProgramList(programs)
//    }
//
//    override fun onLookBackTimeStampChanged(time: Long) {
//        player?.loadingViewControl?.hidePoster()
//
//        var item: ProgramListItem? = null
//        programList?.let {
//            for (i in it.indices) {
//                if (time == -1L && ProgramListItem.getItemState(it[i]) == ProgramListItem.GuideItemState.LIVE) {
//                    item = it[i]
//                    break
//                } else if (it[i].startLong <= time && it[i].endLong >= time) {
//                    item = it[i]
//                    break
//                }
//            }
//        }
//        item?.let {
//            it.playerStart = time
//            handleReplay(it)
//        }
//        if (time == -1L) {
//            item?.startLong?.let {
//                setPlayingStartTime(it)
//            }
//        } else
//            setPlayingStartTime(time)
//    }
//
//    private fun setPlayingStartTime(time: Long) {
//        val simpleDateFormat = SimpleDateFormat("yyyyMMdd", Locale.CHINA)
//        val formatDate = simpleDateFormat.format(time)
//        dateAdapter?.data?.let { items ->
//            for (i in 0 until items.size) {
//                if (items[i].date == formatDate) {
//                    dateAdapter?.selectedIndex = i
//                    programDateList?.scrollToPosition(i)
//                    dateAdapter?.notifyDataSetChanged()
//                    val channel = if (adapterChannelListH!!.data.size > 0) adapterChannelListH!!.data!![adapterChannelListH!!.selectedIndex] else null
//                    if (channel != null)
//                        programFragment?.updateDate(channel, channel?.vid ?: "", formatDate, false, "${channel?.id}", channel?.title)
//                    break
//                }
//            }
//        }
//    }
//}